# eric7.Plugins.CheckerPlugins.CodeStyleChecker.Annotations.AnnotationsChecker

Module implementing a checker for function type annotations.

### Global Attributes

None

### Classes

AnnotationsChecker | Class implementing a checker for function type annotations.

### Functions

None

## AnnotationsChecker

Class implementing a checker for function type annotations.

### Derived from

CodeStyleTopicChecker

### Class Attributes

Category
Codes

### Class Methods

None

### Methods

AnnotationsChecker | Constructor
__argumentErrorClassifier | Private method to classify an argument type annotation issue.
__checkAnnotationComplexity | Private method to check the type annotation complexity.
__checkAnnotationPep604 | Private method to check the use of typing.Union.
__checkAnnotationsCoverage | Private method to check for function annotation coverage.
__checkAnnotationsFuture | Private method to check the use of __future__ and typing imports.
__checkDeprecatedTypingSymbols | Private method to check the use of deprecated 'typing' symbols.
__checkFunctionAnnotations | Private method to check for function annotation issues.
__classifyError | Private method to classify the missing type annotation based on the Function & Argument metadata.
__getAnnotationComplexity | Private method to determine the annotation complexity.
__getAnnotationLength | Private method to determine the annotation length.
__hasTypeAnnotations | Private method to check for type annotations.
__returnErrorClassifier | Private method to classify a return type annotation issue.

### Static Methods

None

#### AnnotationsChecker (Constructor)

AnnotationsChecker(source, filename, tree, select, ignore, expected, repeat, args)

Constructor

source (list of str)
  source code to be checked
filename (str)
  name of the source file
tree (ast.Module)
  AST tree of the source code
select (list of str)
  list of selected codes
ignore (list of str)
  list of codes to be ignored
expected (list of str)
  list of expected codes
repeat (bool)
  flag indicating to report each occurrence of a code
args (dict)
  dictionary of arguments for the annotation checks

#### AnnotationsChecker.__argumentErrorClassifier

__argumentErrorClassifier(isClassMethod, isFirstArg, classDecoratorType, annotationType)

Private method to classify an argument type annotation issue.

isClassMethod (bool)
  flag indicating a classmethod type function
isFirstArg (bool)
  flag indicating the first argument
classDecoratorType (enums.ClassDecoratorType)
  type of class decorator
annotationType (AnnotationType)
  type of annotation

Return:
  error code

Return Type:
  str

#### AnnotationsChecker.__checkAnnotationComplexity

__checkAnnotationComplexity()

Private method to check the type annotation complexity.

#### AnnotationsChecker.__checkAnnotationPep604

__checkAnnotationPep604()

Private method to check the use of typing.Union.

#### AnnotationsChecker.__checkAnnotationsCoverage

__checkAnnotationsCoverage()

Private method to check for function annotation coverage.

#### AnnotationsChecker.__checkAnnotationsFuture

__checkAnnotationsFuture()

Private method to check the use of __future__ and typing imports.

#### AnnotationsChecker.__checkDeprecatedTypingSymbols

__checkDeprecatedTypingSymbols()

Private method to check the use of deprecated 'typing' symbols.

#### AnnotationsChecker.__checkFunctionAnnotations

__checkFunctionAnnotations()

Private method to check for function annotation issues.

#### AnnotationsChecker.__classifyError

__classifyError(function, arg)

Private method to classify the missing type annotation based on the Function & Argument metadata.

For the currently defined rules & program flow, the assumption can be made that an argument passed to this method will match a linting error, and will only match a single linting error

This function provides an initial classificaton, then passes relevant attributes to cached helper function(s).

function (Function)
  reference to the Function object
arg (Argument)
  reference to the Argument object

#### AnnotationsChecker.__getAnnotationComplexity

__getAnnotationComplexity(annotationNode, defaultComplexity=1)

Private method to determine the annotation complexity.

It recursively counts the complexity of annotation nodes. When annotations are written as strings, it additionally parses them to 'ast' nodes.

annotationNode (ast.AST)
  reference to the node to determine the annotation complexity for
defaultComplexity (int (optional))
  default complexity value (defaults to 1)

Return:
  annotation complexity

Return Type:
  = int

#### AnnotationsChecker.__getAnnotationLength

__getAnnotationLength(annotationNode)

Private method to determine the annotation length.

It recursively counts the length of annotation nodes. When annotations are written as strings, it additionally parses them to 'ast' nodes.

annotationNode (ast.AST)
  reference to the node to determine the annotation length for

Return:
  annotation length

Return Type:
  = int

#### AnnotationsChecker.__hasTypeAnnotations

__hasTypeAnnotations(funcNode)

Private method to check for type annotations.

funcNode (ast.AsyncFunctionDef or ast.FunctionDef)
  reference to the function definition node to be checked

Return:
  flag indicating the presence of type annotations

Return Type:
  bool

#### AnnotationsChecker.__returnErrorClassifier

__returnErrorClassifier(isClassMethod, classDecoratorType, functionType)

Private method to classify a return type annotation issue.

isClassMethod (bool)
  flag indicating a classmethod type function
classDecoratorType (ClassDecoratorType)
  type of class decorator
functionType (FunctionType)
  type of function

Return:
  error code

Return Type:
  str

Up